<?php
/*************************************************

消息中心模块公共控制器 - the
Author: WangHuabin <17-10-11>

 *************************************************/
namespace Home\Controller;
use Think\Controller;
class MsgController extends CommonController {
    //发送消息公共方法
    //$typename  消息模版   userid 用戶id
    public function sendmail($typename,$userid,$val=0,$type,$t_id=0,$t_user_id=0,$content=0,$commentid=0){
        if($val==0){
             //查詢消息模版
            $map['typename'] = $typename;
            $msgmodel = M('MessageModel')->where($map)->find();
            $msg_content = $msgmodel['content'];
            $type_id = $msgmodel['type_id'];
            //發送消息
            $data['user_id'] = $userid;
            $data['type_id'] = $type_id;
            $data['content'] = $msg_content;

            $data['add_time'] = time();
            $r = M('Message')->data($data)->add();
        }else{
            //6 赞  7回复  8被拜师 9拜师
            $map['id'] = $t_user_id;
            $user = D('User')->get_one($map);
            $data['type_id'] = $type;
            $data['user_id'] = $userid;
            $data['t_user_id'] = $t_user_id;
            $data['t_id'] = $t_id;
            $data['comment_id'] = $commentid;
            if($type==6){
                $data['content'] = "给您点了一个赞！";
            }elseif($type==7){
                $data['content'] = "回复了您！";
            }elseif($type==8){
                $data['content'] = "拜您为师！";
            }elseif($type==9){
                $data['content'] = "您成功拜TA为师！";
            }elseif($type==10){
                $data['content'] = "回复了您！";
            }elseif($type==11){
                $data['content'] = "回复了您！";
            }elseif($type==12){
                $data['content'] = "回复了您！";
            }elseif($type==13){
                $data['content'] = "回复了您！";
            }elseif($type==14 || $type==15 || $type==16 || $type==17){
                //$data['content'] = $user['nickname']."您收获了一个赞！";
                $data['content'] ="给您点了一个赞！";
            }


            $data['add_time'] = time();

            $r = M('Message')->data($data)->add();
           // echo M('Message')->_sql();
        }
       
    }
}